Skip to content

Fix grouped count aggregation on SQL Server#778

Open
apples-kksk wants to merge 1 commit into
sqlkata:mainfrom
apples-kksk:fix/sqlserver-groupby-removal-774
Open

Fix grouped count aggregation on SQL Server#778
apples-kksk wants to merge 1 commit into
sqlkata:mainfrom
apples-kksk:fix/sqlserver-groupby-removal-774

Conversation

@apples-kksk
Copy link
Copy Markdown

Requested

Issue #774 reports that SQL Server compilation removes GROUP BY from grouped count queries.

Implemented

  • Preserve grouped query shape when transforming single-column AsCount() aggregate queries.
  • Wrap grouped counts in an outer COUNT(*) query while keeping the inner GROUP BY.
  • Added a SQL Server regression test for GroupBy(...).AsCount().

Not covered

No changes to distinct aggregate behavior or unrelated compiler output.

Validated

  • dotnet test /home/molang/bounty-work/querybuilder/sqlkata.sln --filter CountWithGroupBy
  • dotnet build /home/molang/bounty-work/querybuilder/sqlkata.sln
  • git diff --check

Also ran full dotnet test /home/molang/bounty-work/querybuilder/sqlkata.sln; non-MySQL tests passed, while 11 MySqlExecutionTest cases failed because the local MySQL test service is not available in this environment.

@apples-kksk apples-kksk changed the base branch from master to main May 13, 2026 09:03
@apples-kksk apples-kksk force-pushed the fix/sqlserver-groupby-removal-774 branch from ad70835 to a18729b Compare May 13, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant